package net.example.lesson2;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author ${user}
 * @version V1.0
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}(用一句话描述该文件做什么)
 * @date ${date}
 */
public class LinkedHashMapDemo {
    public static void main(String[] args) {
        HashMap<String, String> hashMap = new  HashMap<String, String>(2, 0.75F);
        hashMap.put("abc","ABC");
        hashMap.put("bcd","BCD");
        hashMap.put("cde","CDE");
        hashMap.forEach( (k ,v)->{
            System.out.println(k+":"+v);
        });
        System.out.println(hashMap.get("abc"));
        System.out.println(hashMap.get("bcd"));
        System.out.println(hashMap.get("cde"));
        System.out.println("====================");

        hashMap.put("def","DEF");
        hashMap.put("efg","EFG");
        hashMap.forEach( (k ,v)->{
            System.out.println(k+":"+v);
        });
        System.out.println("=======LinkedHashMap=============");

        LinkedHashMap<String, String> linkedHashMap = new  LinkedHashMap<String, String>(16, 0.75F, true){
            @Override
            protected boolean removeEldestEntry(Map.Entry<String, String> eldest) {

                return size()>3;
            }
        };
        linkedHashMap.put("abc","ABC");
        linkedHashMap.put("bcd","BCD");
        linkedHashMap.put("cde","CDE");
        linkedHashMap.forEach( (k ,v)->{
            System.out.println(k+":"+v);
        });
        System.out.println(linkedHashMap.get("abc"));
        System.out.println(linkedHashMap.get("bcd"));
        System.out.println(linkedHashMap.get("cde"));
        System.out.println("====================");

        linkedHashMap.put("def","DEF");
        linkedHashMap.put("efg","EFG");
        linkedHashMap.forEach( (k ,v)->{
            System.out.println(k+":"+v);
        });
    }
}
